package com.zzg.srb.base.config;


import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket adminApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(adminApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zzg.srb"))
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build().groupName("adminApi");
    }

    @Bean
    public Docket webApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(webApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zzg.srb"))
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build().groupName("webApi");
    }

    /**
     * 添加管理员摘要信息
     */
    private ApiInfo adminApiInfo() {
        // 用ApiInfoBuilder进行定制
        return new ApiInfoBuilder()
                .title("尚融宝后台管理系统API文档")
                .description("描述：接口文档")
                .contact(new Contact("zhengzg", null, null))
                .version("1.0")
                .build();
    }

    /**
     * 添加web摘要信息
     */
    private ApiInfo webApiInfo() {
        // 用ApiInfoBuilder进行定制
        return new ApiInfoBuilder()
                .title("尚融宝web系统API文档")
                .description("描述：接口文档")
                .contact(new Contact("zhengzg", null, null))
                .version("1.0")
                .build();
    }
}
